﻿// ———————————————————————–
// <copyright file="IncidentPulsePointStatusCode.cs" company="The MITRE Corporation">
//    Copyright (c) 2014 The MITRE Corporation. All rights reserved.
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//    http://www.apache.org/licenses/LICENSE-2.0
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
// </copyright>
// ———————————————————————–
/////////////////////////////////////////////////////////////////////////////////////////////////
// IncidentPulsePointStatusCode.cs:
//
// Primary statuses based off PulsePoint API
//
// Project: IC.NET - CAD Library
// Author:  Jim Cronin - MITRE
/////////////////////////////////////////////////////////////////////////////////////////////////

// Copyright (c) 2014 The MITRE Corporation. All rights reserved.
//
// NOTICE
// This software was produced for the U. S. Government
// under Contract No. FA8721-09-C-0001, and is
// subject to the Rights in Noncommercial Computer Software
// and Noncommercial Computer Software Documentation Clause
// (DFARS) 252.227-7014 (JUN 1995)

using System;

namespace EDXLSharp.NIEMCADLib
{
  /// <summary>
  /// Primary statuses based off PulsePoint API
  /// </summary>
  public enum IncidentPulsePointStatusCode
  {
    /// <summary>
    /// A call for a paritcular incident has been received
    /// </summary>
    CallReceived,

    /// <summary>
    /// An EMS determinate code has been assigned
    /// </summary>
    EMSDeterminantComplete,

    /// <summary>
    /// Units have been dispatched
    /// </summary>
    Dispatch,

    /// <summary>
    /// Units are enroute
    /// </summary>
    Enroute,

    /// <summary>
    /// The first unit has arrived at the scene
    /// </summary>
    OnScene,

    /// <summary>
    /// The incident has been declared a "working fire"
    /// </summary>
    WorkingFire,

    /// <summary>
    /// The first ambulance has arrived
    /// </summary>
    AmbulanceArrived,

    /// <summary>
    /// Agency personnel has arrived at the patient
    /// </summary>
    PatientSide,

    /// <summary>
    /// The incident has been declared "under control"
    /// </summary>
    UnderControl,

    /// <summary>
    /// The last unit assigned to the incident has been cleared from the incident.
    /// </summary>
    Closed
  }

  public static class IncidentPulsePointStatusCodeExtensions
  {
    /// <summary>
    /// Gets the text to be written to XML for the EventTypeCode
    /// </summary>
    /// <param name="code">The <see cref="EDXLSharp.NIEMCADLib.IncidentPulsePointStatusCode"/> to convert to text</param>
    /// <returns>Text representation of the <see cref="EDXLSharp.NIEMCADLib.IncidentPulsePointStatusCode"/></returns>
    public static string GetText(this IncidentPulsePointStatusCode code)
    {
      switch (code)
      {
        case IncidentPulsePointStatusCode.CallReceived:
          return "CALL RECEIVED";
        case IncidentPulsePointStatusCode.EMSDeterminantComplete:
          return "EMS DETERMINANT COMPLETE";
        case IncidentPulsePointStatusCode.Dispatch:
          return "DISPATCH";
        case IncidentPulsePointStatusCode.Enroute:
          return "ENROUTE";
        case IncidentPulsePointStatusCode.OnScene:
          return "ON SCENE";
        case IncidentPulsePointStatusCode.WorkingFire:
          return "WORKING FIRE";
        case IncidentPulsePointStatusCode.AmbulanceArrived:
          return "AMBULANCE ARRIVED";
        case IncidentPulsePointStatusCode.PatientSide:
          return "PATIENT SIDE";
        case IncidentPulsePointStatusCode.UnderControl:
          return "UNDER CONTROL";
        case IncidentPulsePointStatusCode.Closed:
          return "CLOSED";
        default:
          throw new ArgumentException("Not a known value for IncidentPulsePointStatusCode: " + code.ToString());
      }
    }

    /// <summary>
    /// Converts a text value to an <see cref="EDXLSharp.NIEMCADLib.IncidentPulsePointStatusCode"/>
    ///  - First checks for the XML text of each code
    ///  - Lastly just calls Enum.Parse
    /// </summary>
    /// <param name="value">String to parse</param>
    /// <returns><see cref="EDXLSharp.NIEMCADLib.IncidentPulsePointStatusCode"/> described by value</returns>
    /// <exception cref="System.ArgumentNullException">Thrown if value is null</exception>
    /// <exception cref="System.ArgumentException">Thrown if value is empty or whitespace</exception>
    /// <exception cref="System.OverflowException">Thrown if value does not represent an <see cref="EDXLSharp.NIEMCADLib.IncidentPulsePointStatusCode"/></exception>
    public static IncidentPulsePointStatusCode GetCode(string text)
    {
      switch (text)
      {
        case "CALL RECEIVED":
          return IncidentPulsePointStatusCode.CallReceived;
        case "EMS DETERMINANT COMPLETE":
          return IncidentPulsePointStatusCode.EMSDeterminantComplete;
        case "DISPATCH":
          return IncidentPulsePointStatusCode.Dispatch;
        case "ENROUTE":
          return IncidentPulsePointStatusCode.Enroute;
        case "ON SCENE":
          return IncidentPulsePointStatusCode.OnScene;
        case "WORKING FIRE":
          return IncidentPulsePointStatusCode.WorkingFire;
        case "AMBULANCE ARRIVED":
          return IncidentPulsePointStatusCode.AmbulanceArrived;
        case "PATIENT SIDE":
          return IncidentPulsePointStatusCode.PatientSide;
        case "UNDER CONTROL":
          return IncidentPulsePointStatusCode.UnderControl;
        case "CLOSED":
          return IncidentPulsePointStatusCode.Closed;
        default:
          return (IncidentPulsePointStatusCode)Enum.Parse(typeof(IncidentPulsePointStatusCode), text);
      }
    }
  }
}
